{{template "admin/layout/header_full.html" .}}
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">站点名称</label>
        <div class="layui-input-block">
            <input type="text" name="site_name" required lay-verify="required" placeholder="请输入站点名称" autocomplete="off"
                   class="layui-input" value="{{ .site_name }}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">站点Logo</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="upload">
                <i class="layui-icon">&#xe67c;</i>上传
            </button>
        </div>
        <div class="layui-input-block">
            <div class="layui-col-md4">
                <input class="mbg-logo" type="image" src="{{ .site_logo }}"
                       name="site_logo" id="site_logo" value="{{ .site_logo }}" onclick="return false;">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">站点URL</label>
        <div class="layui-input-block">
            <input type="text" name="site_url" placeholder="请输入站点URL" autocomplete="off" class="layui-input"
                   value="{{ .site_url }}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">站点关键字</label>
        <div class="layui-input-block">
            <input type="text" name="site_keyword" placeholder="请输入站点关键字" autocomplete="off" class="layui-input"
                   value="{{ .site_keyword }}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">站点描述</label>
        <div class="layui-input-block">
            <input type="text" name="site_describe" placeholder="请输入站点描述" autocomplete="off" class="layui-input"
                   value="{{ .site_describe }}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">客服电话</label>
        <div class="layui-input-block">
            <input type="text" name="site_mobile" placeholder="请输入客服电话" autocomplete="off" class="layui-input"
                   value="{{ .site_mobile }}">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="systemSave">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    layui.use(['form', 'upload', 'jquery'], function () {
        var form = layui.form;
        var upload = layui.upload;
        var $ = layui.jquery;

        //监听提交
        form.on('submit(systemSave)', function (data) {
            layer.load();
            $.post("/admin/system/save", data.field, function (res) {
                layer.closeAll("loading");
                layer.msg(res.message);
                if (res.code === 0) {
                    setTimeout(function () {
                        location.reload()
                    }, 1500)
                }
            });
            return false;
        });

        //监听上传
        upload.render({
            elem: '#upload',
            url: '/upload/upload',
            accept: 'images',
            before: function (obj) {
                layer.load();
            },
            done: function (res) {
                layer.closeAll("loading");
                if (res.code === 0) {
                    $("#site_logo").attr('src', res.data.src);
                    $("#site_logo").attr('value', res.data.src);
                }
            }
        });
    });
</script>
{{template "admin/layout/footer_full.html" .}}